using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ACM.cmsarea08;
using ACM.cmsarea08.Controls;
using ACM.cmsarea08.Administration;


namespace ACM.cmsarea08.Administration.Core {
	public partial class BaseEditPage :  ACM.cmsarea08.Administration.Core.AdminPage {
		public ACM.cmsarea08.Controls.Itan_FormEditor myform;
		public ACM.cmsarea08.Administration.Controls.MainButton adm_buttons;
		protected override void OnPreInit(EventArgs e)
		{
			base.OnPreInit(e);
			//Response.Write("SONO PINO:" + ACM.cmsarea08.Users.CurrentUser.UserName);
			if(ACM.cmsarea08.Users.CurrentUser.SimpleAdmin==true) {
				if(this.Page.Master==null) return;
				if(string.IsNullOrEmpty(this.Page.MasterPageFile)) return;
				 string currentFile = this.Page.MasterPageFile;
				 if(currentFile.IndexOf("dummy")!=-1) return;
				 if(currentFile.IndexOf("administration/")!=-1) {
				 	currentFile = currentFile.Insert(currentFile.LastIndexOf("/administration/")+16,"dummy");
				 	this.Page.MasterPageFile = currentFile;
				 }
			}
		}			
		override protected void OnInit(EventArgs e)
		{

			
			InitializeComponent();
			base.OnInit(e);
		}
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
		}
	
		private void Page_Load(object o , EventArgs e) {
			
//			this.Page.Controls.Add(new LiteralControl(js));			
			
		}
		
		
		protected override void Render(HtmlTextWriter writer)
		{
			string js = "";
			js+="<script language=\"javascript\" type=\"text/javascript\" defer=\"defer\">";
			js+="\n\r//<![CDATA[\n\rwindow.addEvent('domready', function() {";
			js+=" LockToolbar(); ";
			js+="});\n\r//]]>\n\r";
			js+="</script>";
			System.IO.StringWriter _writer = new System.IO.StringWriter();
			HtmlTextWriter buffer = new HtmlTextWriter(_writer);
			base.Render(buffer);
			string currentPage = _writer.ToString();
			int endFormPos = currentPage.IndexOf("</form>");
			if(endFormPos==-1) {
				endFormPos = currentPage.IndexOf("</body>");
				if(endFormPos==-1) endFormPos =currentPage.Length;
			} 
			currentPage  = currentPage.Insert(endFormPos,js);
			writer.Write(currentPage);			
		}
		
		public void PrintMessage(string message) {
			if(adm_buttons!=null) {
				adm_buttons.ShowResultMessage(message);
			} else
				HttpContext.Current.Response.Write("<hr>" + message + "<hr>");
		}
	}
	
}
	